local skel = fk.CreateSkill {
  name = "efengqi__juyi_other&",
}

Fk:loadTranslationTable{
  ["efengqi__juyi_other&"] = "聚义",
  [":efengqi__juyi_other&"] = "每轮每种牌名限一次，你可以将三张同色牌交给有“聚义”的角色，视为使用一张基本牌",
  ["#efengqi__juyi-other"] = "选择你要视为使用的基本牌，将三张同色牌交给有“聚义”的角色",
}

skel:addEffect("viewas", {
  prompt = "#efengqi__juyi-other",
  pattern = ".|.|.|.|.|basic",
  interaction = function (self, player)
    local all_names = {}
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if p ~= player and p:hasSkill("efengqi__juyi") then
        table.insertTableIfNeed(all_names, p:getTableMark("@$efengqi__juyi"))
      end
    end
    local names = player:getViewAsCardNames(skel.name, all_names)
    if #names > 0 then
      return UI.CardNameBox { choices = names }
    end
  end,
  card_filter = function (self, player, to_select, selected, selected_targets)
    return #selected < 3 and (#selected == 0 or table.every(selected, function (id)
      return Fk:getCardById(id).color == Fk:getCardById(to_select).color
    end))
  end,
  view_as = function (self, player, cards)
    if Fk.all_card_types[self.interaction.data] == nil then return nil end
    if #cards ~= 3 then return nil end
    local card = Fk:cloneCard(self.interaction.data)
    card:setMark(skel.name, cards)
    card.skillName = skel.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local cards = use.card:getMark(skel.name)
    if cards == 0 then return "" end
    room:setCardMark(use.card, skel.name, 0)
    local targets = table.filter(room.alive_players, function (p)
      return p ~= player and p:hasSkill("efengqi__juyi") and table.find(p:getTableMark("@$efengqi__juyi"), function (name)
        return Fk:cloneCard(name).trueName == use.card.trueName
      end)
    end)
    if #targets == 0 then return "" end
    local to = #targets == 1 and targets[1] or room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, targets = targets, skill_name = skel.name, cancelable = false,
    })[1]
    local mark = table.filter(to:getTableMark("@$efengqi__juyi"), function (name)
      return Fk:cloneCard(name).trueName ~= use.card.trueName
    end)
    room:setPlayerMark(to, "@$efengqi__juyi", #mark > 0 and mark or 0)
    room:obtainCard(to, cards, false, fk.ReasonGive, player, "efengqi__juyi")
  end,
  enabled_at_play = function(self, player)
    return #player:getCardIds("he") > 2
    and table.find(Fk:currentRoom().alive_players, function (p)
      return p ~= player and p:hasSkill("efengqi__juyi") and p:getMark("@$efengqi__juyi") ~= 0
   end)
  end,
  enabled_at_response = function(self, player, response)
    return not response and Fk.currentResponsePattern and #player:getCardIds("he") > 2
    and table.find(Fk:currentRoom().alive_players, function (p)
      return p ~= player and p:hasSkill("efengqi__juyi") and table.find(p:getTableMark("@$efengqi__juyi"), function (name)
        return Exppattern:Parse(Fk.currentResponsePattern):matchExp(".|.|.|.|" .. name) -- 注意，标记里存的是name而非trueName
      end)
    end)
  end,
})



return skel
